using ClockLib.Logger;
using ClockLib;
using ClockServer.Services;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using ClockServer.Extensions;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddSingleton<ClockLib.Logger.ILogger>(new ConsoleLogger());

builder.Services.AddSingleton<ClockSettings>(ClockSettings.Load());
builder.Services.AddSingleton<Clock>();
builder.Services.AddHostedService<ClockService>();

var app = builder.Build();

#if DEBUG
    app.UseSwagger();
    app.UseSwaggerUI();
#endif

app.UseGlobalExceptionHandler();
//app.UseAuthorization();
app.UseDefaultFiles();
app.UseStaticFiles();
app.MapControllers();

app.Run("http://127.0.0.1:8000");
